require 'hostmenu'
require 'joinmenu'
local class = require 'hump.class'
local gwee = require 'gwee.gwee'
local state = require 'hump.gamestate'
local text = require 'utilities.text'

MainMenu = class{
  function(self)
    self.w = love.graphics.getWidth()
    self.h = love.graphics.getHeight()
    
    self.mainmenustate = state.new()
    self.mainmenustate.enter = self.enter
    self.mainmenustate.leave = self.leave
    self.mainmenustate.keypressed = self.keypressed
    self.mainmenustate.mousepressed = self.mousepressed
    self.mainmenustate.mousereleased = self.mousereleased
    self.mainmenustate.update = self.update
    self.mainmenustate.draw = self.draw
    
    state.registerEvents()
    
    self.mainmenustate.group = gwee.Group(gwee.Box(self.w/2-100, self.h/2-100, 200, 200), gwee.VerticalLayout(5), 'Main Menu')
    self.mainmenustate.group:add(gwee.Button(function() HostMenu(state, self.mainmenustate) end, 'Host Game'))
    self.mainmenustate.group:add(gwee.Button(function() JoinMenu(state, self.mainmenustate) end, 'Join Game'))
    self.mainmenustate.group:add(gwee.Button(function() os.exit() end, 'Exit'))
    
    state.switch(self.mainmenustate)
  end
}

function MainMenu:enter()
  self.group.enabled = true
end

function MainMenu:leave()
  self.group.enabled = false
end

function MainMenu:keypressed(key)
  gwee.keypressed(key)
end

function MainMenu:mousepressed(x, y, button)
  gwee.mousepressed(x, y, button)
end

function MainMenu:mousereleased(x, y, button)
  gwee.mousereleased(x, y, button)
end

function MainMenu:update(dt)
  gwee.update(dt)
end

function MainMenu:draw()
  text.drawCenterText('Gravit T', 0, 36)
  gwee.draw()
end
